<?php

    define('BIORHYTHM_CYCLE_PHYSICAL',     23);
    define('BIORHYTHM_CYCLE_EMOTIONAL',    28);
    define('BIORHYTHM_CYCLE_INTELLECTUAL', 33);

class biorhythm
{

    static function rhythm($birthday_date, $today_date, $cycle)
    {
        $birthday = floor($birthday_date / SEC_IN_DAY);
        $today    = floor($today_date / SEC_IN_DAY);
        $days     = $today - $birthday;
        
        $percentage_of_cycle = ( $days % $cycle ) / $cycle;
        $result = sin(PI2 * $percentage_of_cycle);
        $result = $result > 1 ? 1 : $result < -1 ? -1 : $result;
        
        return $result;  // [-1, 1]
    }
    
    static function physical($birthday_date, $today_date)
    {
        return biorhythm::rhythm($birthday_date, $today_date, BIORHYTHM_CYCLE_PHYSICAL);
    }
    
    static function emotional($birthday_date, $today_date)
    {
        return biorhythm::rhythm($birthday_date, $today_date, BIORHYTHM_CYCLE_EMOTIONAL);
    }
    
    static function intellectual($birthday_date, $today_date)
    {
        return biorhythm::rhythm($birthday_date, $today_date, BIORHYTHM_CYCLE_INTELLECTUAL);
    }

}
    
?>